<?php
  require_once('./includes/header.php');
  #rasmus123@gmail.com' OR '1'='1

  if(isset($_SESSION['id']) && !empty($_SESSION['id'])){
    header("location:show_all_users.php");
    exit;
  }


  if(isset($_POST['email']) && !empty($_POST['email'])
  && isset($_POST['password']) && !empty($_POST['password']))
  {
    $email = mysql_real_escape_string(trim($_POST['email']));
    $password = md5(mysql_real_escape_string(trim($_POST['password'])));

    $where = "`email`='$email' AND `password`='$password' AND `status`='1' AND `id`='1'";

    /*******************************/
    $result = fetchAll('users',$where);
    /*******************************/
    $rows = mysql_num_rows($result);
    if($rows == 1){
      $user = mysql_fetch_assoc($result);
      //pr($user);
      $time = time()+20;

if(isset($_POST['remember'])) {
      setcookie('email',$_POST['email'], $time);
      setcookie('password',$_POST['password'], $time);
} else {
      setcookie('email',$_POST['email'], time()-1);
      setcookie('password',$_POST['password'], time()-1);
}

      $_SESSION['id'] = $user['id'];
      $_SESSION['uname'] = $user['uname'];
      $_SESSION['email'] = $user['email'];
      header("location:show_all_users.php");
      exit;
    } else {
      $msg = "Email / Password incorrect.";

    }
    //pr($rows);
  } else {
    if(!empty($_POST)){
      $msg = "Email / Password should not be blank.";
    }
  }
?>
<!------------------HEADER ENDS-------------------------->

      <div class="row">

<?php
if($msg != '') {
?>
    <div class="alert alert-danger fade in">
      <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
      <p><?=$msg?></p>
    </div>
<?php
}
?>


<!----------------  FORM ------------>
      <form method="post" class="form-signin" role="form">
        <h2 class="form-signin-heading">Please sign in</h2>
        <input name="email" value="<?=@$_COOKIE['email']?>" type="email123" class="form-control" placeholder="Email address"  autofocus>
        <input name="password"  value="<?=@$_COOKIE['password']?>" type="password" class="form-control" placeholder="Password" >
        <label class="checkbox">
          <input type="checkbox" checked name="remember"> Remember me
        </label>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
        <a href="forgot_password.php">Forgot password</a>
      </form>

rasmus123@gmail.com / 1q1q1q
<!----------------  FORM ------------>
      </div>
<!-------------- FOOTER START --------------------------->
    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">
<?php
  require_once('./includes/footer.php');
?>
